/**********************************************************************
* Filename: Aeroporto.java
* Created: 2013/05/31
* @author Fernando Brito e Abreu
**********************************************************************/
package org.quasar.airNova.businessLayer;

import org.quasar.airNova.persistenceLayer.Database;

import java.util.Set;
import java.util.HashSet;

public class Aeroporto
{
	
	/***********************************************************
	* @return all instances of class Aeroporto
	***********************************************************/
	public static Set<Aeroporto> allInstances()
	{
		return Database.allInstances(Aeroporto.class);
	}
	
	private String nome;
	
	/**********************************************************************
	* Default constructor
	**********************************************************************/
	public Aeroporto()
	{
	}
	
	/**********************************************************************
	* Parameterized constructor
	* @param nome the nome to initialize
	**********************************************************************/
	public Aeroporto(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* Standard attribute getter
	* @return the nome of the aeroporto
	**********************************************************************/
	public String nome()
	{
		return nome;
	}
	
	/**********************************************************************
	* Standard attribute setter
	* @param nome the nome to set
	**********************************************************************/
	public void setNome(String nome)
	{
		this.nome = nome;
	}
	
	/**********************************************************************
	* ONE2MANY getter for Aeroporto[1] <-> Voo[*]
	* @return the voos_chegada of the chegada
	**********************************************************************/
	public Set<Voo> voos_chegada()
	{
		Set<Voo> result = new HashSet<Voo>();
		for (Voo x : Voo.allInstances())
			if (x.chegada()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY multiple setter for Aeroporto[1] <-> Voo[*]
	* @param voos_chegada the voos_chegada to set
	**********************************************************************/
	public void setVoos_chegada(Set<Voo> voos_chegada)
	{
		for (Voo x : voos_chegada)
			x.setChegada(this);
	}
	
	/**********************************************************************
	* ONE2MANY single setter for Aeroporto[1] <-> Voo[*]
	* @param voo the voo to add
	**********************************************************************/
	public void addVoos_chegada(Voo voo)
	{
		voo.setChegada(this);
	}
	
	/**********************************************************************
	* ONE2MANY getter for Aeroporto[1] <-> Voo[*]
	* @return the voos_partida of the partida
	**********************************************************************/
	public Set<Voo> voos_partida()
	{
		Set<Voo> result = new HashSet<Voo>();
		for (Voo x : Voo.allInstances())
			if (x.partida()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* ONE2MANY multiple setter for Aeroporto[1] <-> Voo[*]
	* @param voos_partida the voos_partida to set
	**********************************************************************/
	public void setVoos_partida(Set<Voo> voos_partida)
	{
		for (Voo x : voos_partida)
			x.setPartida(this);
	}
	
	/**********************************************************************
	* ONE2MANY single setter for Aeroporto[1] <-> Voo[*]
	* @param voo the voo to add
	**********************************************************************/
	public void addVoos_partida(Voo voo)
	{
		voo.setPartida(this);
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE getter for Aeroporto[*] <-> Proximidade[*]
	* @return the proximidade of the servem
	**********************************************************************/
	public Set<Proximidade> proximidade()
	{
		Set<Proximidade> result = new HashSet<Proximidade>();
		for (Proximidade x : Proximidade.allInstances())
			if (x.servem()  ==  this)
				result.add(x);
		return result;
	}
	
	/**********************************************************************
	* MEMBER2ASSOCIATIVE setter for Aeroporto[*] <-> Proximidade[*]
	* @param proximidade the proximidade to set
	**********************************************************************/
	public void setProximidade(Set<Proximidade> proximidade)
	{
		for (Proximidade x : proximidade)
			x.setServem(this);
	}
	
	/**********************************************************************
	* MEMBER2MEMBER getter for Aeroporto[*] <-> Cidade[*]
	* @return the servidas of the servem
	**********************************************************************/
	public Set<Cidade> servidas()
	{
		Set<Cidade> result = new HashSet<Cidade>();
		for (Proximidade x : Proximidade.allInstances())
			if (x.servem()  ==  this)
				result.add(x.servidas());
		return result;
	}
	
	/**********************************************************************
	* MEMBER2MEMBER setter for Aeroporto[*] <-> Cidade[*]
	* @param servidas the servidas to set
	**********************************************************************/
	public void setServidas(Set<Cidade> servidas)
	{
		for (Cidade t : servidas)
			for (Proximidade x : Proximidade.allInstances())
				if (x.servem() == this)
					x.setServidas(t);
	}
	
	/**********************************************************************
	* Object serializer
	**********************************************************************/
	public String toString()
	{
		return "Aeroporto [nome=" + nome + "]";
	}
	
	//	-------------------------------------------------------------------------------
	//	INVARIANTS (TODO)
	/*
	inv paisValido
		self.servidas->forAll(c1 : Cidade, c2 : Cidade | ((c1.pais <> c2.pais) implies (c1.pais.nome = c2.pais.nome)))
	
	*/
}
